// Copyright 2022 NullPTR. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "FRGBABitmap.h"

namespace SDFGen
{
	/**
	* 把灰度图转换为线性的Signed Distance Field图像
	*/
	class SDFGEN_API FSDFUtils
	{
	protected:
		struct Point
		{
			int dx;
			int dy;

			int DistSq() const { return dx*dx + dy*dy; }
		};

		struct Grid
		{
			Point* grid;
		};
		
	public:
		FSDFUtils();
		~FSDFUtils();
		
		void Generate(const FRGBABitmap* src, FRGBABitmap* dest);
		void Generate(const FImage* src, FImage* dest);

	private:
		Point GetGrid(const Grid& g, int x, int y) const;
		void PutGrid(Grid& g, int x, int y, const Point& p);
		void Compare(const Grid& g, Point& p, int x, int y, int offsetx, int offsety);

		void GeneratePass(Grid& g);

	private:
		const Point INSIDE_POINT = {0, 0};
		const Point EMPTY_POINT = {9999, 9999};

		int width;
		int height;
		Grid grid1;
		Grid grid2;
	};
}
